/**
 * 数据库连接对象获取
 * Created by marker on 14-3-25.
 */

var mysql = require("mysql");

// 数据库配置
var config = {
    host: "localhost",
    user: "root",
    password: "123456",
    database:"bagShop" ,
    insecureAuth: true
}
// 数据库连接池
var pool  = mysql.createPool(config);



/**
 * 获取数据库连接
 * @returns {*}
 */
exports.getConnection = function(){
    return mysql.createConnection(config);
}


/**
 * 通过连接池获取数据库连接
 * [效率更高]
 * @param callback 回调函数 function(err, connection){ }
 */
exports.pool = function(callback){
    pool.getConnection(callback);
}

/**
 * 关闭数据库连接
 * @param connection 连接对象
 */
exports.closeCon = function(connection) {
    connection.destroy();
};